import { t } from 'i18next'
import createVanilla from 'zustand/vanilla'
import create from 'zustand'
import {
	chnInfoEntity,
	defaultData,
	ErrorCometd,
	MyHduCache,
	MyUsedStyleEntity,
	Poll,
	TvWallBatchpollCometd,
	TvWallCometd,
	Vmp,
} from './interface'
import { filterMtName, getUrlParams } from '@/utils'
import {
	fetchChangeIfShowMTName,
	fetchChnageStyleInfo,
	fetchGetAllTvwallStyles,
	fetchGetMTChnInfo,
	fetchGetStylesByMeetingMoidInfo,
	fetchGetStylesDetailInfo,
	fetchGetTvWallPlanList,
} from '@/api/manager/tvwall'
import { Alert, confirmModal } from '@/components/Alert'
import { Message, Modal } from '@kedacom/react-next'
import { batchPollEntity, BoxInfoEntity, StyleDetail, TvWallMemberItemEntity } from '@/api/manager/tvwall/interface'
import { Mt, MtEntity } from '@/api/manager/mt'
import { getTvWallTypeName, isEqualMtchnids } from './translator'
import { useMccStore } from '../../store'
export interface InitTvWallOption {
	/** 弹窗是否打开 */
	isOpen: boolean
	meetingMoid: string
	/** 会议类型 0-传统会议 1-端口会议 2-rtc会议 */
	meetingType: 0 | 1 | 2
	/** 是否级联 */
	isCascade: boolean
	/** 常用终端 */
	oftenMembers: Mt[]
	/** 本级在线终端 */
	batchMembers: Mt[]
	/** 画面合成数据 */
	data: Vmp
	/**	/**将所有的电视墙风格变成id=>item 对象*/
	style_map: {
		[key: string]: BoxInfoEntity
	}
	config: {
		maxCell: number
		minWidth: number
		container: string
		containerW: number
		containerH: number
		MCCcontainerW: number
		previewW: number
		currentviewW: number
	}
	/**预案名称 */
	preName: string
	preBatchPollName: string
	/**显示终端名称 */
	show_mt_name: number
	/**电视墙开启状态 */
	state: number
	/**电视墙模式 */
	mode: number
	/**当前会议使用的风格 */
	my_used_style: MyUsedStyleEntity
	/**当前选中的电视墙风格 */
	correct_style: string
	/**自身缓存的HDU */
	my_hdu_cache: Array<MyHduCache>
	/**是否可编辑 */
	is_editing: boolean
	/**四分屏弹框的开启 */
	isFourScreenOpen: boolean
	/**单通道轮询模态框开启 */
	isSinglePollOpen: boolean
	/**自主多画面模态框开启 */
	isVMPOpen: boolean
	/**声音弹框开启 */
	isOpenVolumeModal: boolean
	/**更新表识 */
	updateFlag: boolean
	/**全局 */
	globalSwitchView: any
	/**根据style_id确定盒子的内容 */
	boxDetailVOsSource: Array<TvWallMemberItemEntity>
	/**每个盒子的错误码 */
	boxDetailVOsSourceErrorCode: { [key: string]: number | string }
	id: string
	/**预案名称 */
	name: string
	/**轮询次数，0表示无限次轮询 */
	num: number
	/**轮询间隔时间(秒) */
	keep_time: number
	/**轮询成员 */
	tvWallBatchMembers: Array<MtEntity>
	/**接口获取到的批量轮询数据 */
	batch_poll: batchPollEntity | null
	show_batch_poll: Poll | null
	/**点击操作的元素的位置(管理方跟随、发言方跟随、等等) */
	operateBoxInfo: TvWallMemberItemEntity | null
	operateBoxInfoIndex: number
	isAddStyleModalOpen: boolean
	showUI: boolean
	isFourScreen: boolean
	is_batch_poll: boolean
}
type TvWallStore = InitTvWallOption & {
	update: (d: Partial<InitTvWallOption>) => void
	updateData: (d: Vmp | null) => void
	reset: () => void
	onClose: () => void
	onInit: () => void
	/**获取所有的电视墙风格列表 */
	loadAllStyle: () => void
	/**获取会议的电视墙风格列表 _id是指会议的meetingMoid*/
	getMccTVWallsByMeetingMoid: (_id: string, callback?: () => void) => void
	/**加载风格详情 id是指风格id*/
	loadTvwallStyle: (_id: string, callback?: (_data?: StyleDetail) => void) => void
	/**获取码率 */
	getRate: (_type: string) => number
	// /**加载电视墙风格信息 传递风格id*/
	// getTVWallByMeetingMoidAndStyle: (_id: string) => void
	/**更新自己会议的HDU */
	updateMyMeetingHdu: (_data: StyleDetail) => void
	/**是否显示终端名称*/
	setHduShowName: (_flag: boolean) => void
	convertMsg: (_data: TvWallMemberItemEntity, index?: number) => void
	/**编辑 */
	handleModifyIn: () => void
	/**退出编辑 */
	handleModifyOut: () => void
	/**关闭电视墙模态框 */
	handleCloseTvwallModal: () => void
	/**停止批量轮询 */
	handleStopBatchPoll: () => void
	/**切换模式 */
	handleChangeMode: (mode: number) => void
	handleSendChannelVmp: (vmp: any) => void
	removeStreamDom: () => void
	changeTVWallChannel: (_data: any) => void
	getMTChnInfo: (mt: any, callBack: (chn_info: Array<chnInfoEntity>) => void) => void
	streamDomData: (mt: any) => { mt_key: string | null; mt_id: string | null }
	msgHandle: (_data: TvWallCometd) => void
	checkCurStyle: (_data: TvWallBatchpollCometd) => boolean
	batchpollhandle: (_data: TvWallBatchpollCometd) => void
	errorHandle: (_data: ErrorCometd) => void
	/**移除错误提示*/
	removeErrorMark: (_hdu_id: string) => void
}
const initialState: InitTvWallOption = {
	isOpen: false,
	meetingMoid: getUrlParams('meetingMoid') ?? '',
	meetingType: 1,
	isCascade: false,
	oftenMembers: [],
	batchMembers: [],
	data: defaultData,
	style_map: {},
	config: {
		maxCell: 10, //纵向或横向单元格最大数
		minWidth: 190,
		container: '',
		containerW: 900,
		containerH: 588,
		MCCcontainerW: 520,
		previewW: 135,
		currentviewW: 64,
	},
	preName: '',
	show_mt_name: 0,
	state: 0,
	mode: 1,
	/**会议使用到的电视墙风格*/
	my_used_style: [],
	my_hdu_cache: [],
	correct_style: '',
	is_editing: false,
	isFourScreenOpen: false,
	isVMPOpen: false,
	isSinglePollOpen: false,
	globalSwitchView: {},
	isOpenVolumeModal: false,
	updateFlag: false,
	boxDetailVOsSource: [],
	boxDetailVOsSourceErrorCode: {},
	preBatchPollName: '',
	num: 0,
	keep_time: 30,
	tvWallBatchMembers: [],
	operateBoxInfo: null,
	operateBoxInfoIndex: 0,
	isAddStyleModalOpen: false,
	showUI: false,
	isFourScreen: false,
	name: '',
	id: '',
	batch_poll: null,
	show_batch_poll: null,
	is_batch_poll: false,
}
export const store = createVanilla<TvWallStore>((set, get) => ({
	...initialState,
	update: (d) => set({ ...d }),
	updateData: (data) => {
		let _data: Vmp = data ?? defaultData
		if (get().meetingType === 2) {
			_data.mode = 1
			_data.layout = 5
		}
		set({ data: _data })
	},
	reset: () => set(initialState),
	onClose: () => {},
	onInit: () => {},
	/**获取所有的电视墙风格列表 */
	loadAllStyle: async () => {
		const { meetingMoid, getMccTVWallsByMeetingMoid } = get()
		const callback = () => {
			fetchGetTvWallPlanList(meetingMoid)
		}
		getMccTVWallsByMeetingMoid(meetingMoid, callback)
	},
	/**获取会议使用的电视墙风格 */
	getMccTVWallsByMeetingMoid: async (meeting_id) => {
		const { loadTvwallStyle } = get()
		const res = await fetchGetStylesByMeetingMoidInfo(meeting_id)
		if (res.success) {
			if (res.data) {
				let _my_used_style = res.data.styles || []
				let _name = res.data.name || ''
				set({ my_used_style: _my_used_style, preName: _name })
				/**当前电视墙无风格 */
				if (!_my_used_style.length) {
					set({
						my_used_style: [],
						preName: '',
						show_mt_name: 1,
						preBatchPollName: '',
						correct_style: '',
						mode: 1,
						boxDetailVOsSource: [],
						boxDetailVOsSourceErrorCode: {},
					})
				} else {
					var _id = _my_used_style[0]?.id /**第一条数据的id */
					/**加载详情(存在风格id加载详情)*/
					_id && loadTvwallStyle(_id)
				}
			}
		} else {
			Alert(t('获取电视墙配置失败'))
			set({ my_used_style: [], preName: '', show_mt_name: 1, preBatchPollName: '', correct_style: '', mode: 1 })
		}
	},
	/**加载电视墙风格详情*/
	loadTvwallStyle: async (style_id) => {
		const { meetingMoid } = get()
		const mask = Message.loading(t('正在加载电视墙风格'))
		let res = await fetchGetStylesDetailInfo(meetingMoid, style_id)
		mask.hide()
		if (res.success) {
			if (res.data) {
				const {
					id = '',
					keep_time = 30,
					num = 0,
					name = '',
					members = [],
					mode = 1,
					cur_poll_mt = undefined,
					batch_id = '',
				} = res.data?.batch_poll || {}
				let _show_batch_poll = {
					id: id,
					keep_time: keep_time,
					num: num,
					name: name,
					members: members,
					mode: mode,
					cur_poll_mt,
				}
				set({
					mode: res.data.mode || 1,
					show_mt_name: res.data.show_mt_name || 0 /**是否显示终端名称 */,
					state: res.data?.batch_poll?.state || 0 /**批量轮询状态 */,
					is_batch_poll: res.data?.batch_poll?.state ? true : false,
					boxDetailVOsSource: res.data.members || [],
					correct_style: style_id,
					batch_poll: Object.assign({ batch_id: batch_id }, _show_batch_poll),
					show_batch_poll: new Poll(_show_batch_poll),
				})
			}
		} else {
			Alert(t('获取电视墙配置失败'))
			set({ my_used_style: [], preName: '', show_mt_name: 1, preBatchPollName: '', correct_style: '', mode: 1 })
		}
	},
	/**切换模式 */
	handleChangeMode: (mode) => {
		const { handleStopBatchPoll, state } = get()
		if (mode === 1) {
			confirmModal({
				msg: t('选择定制画面将停止当前的批量轮询，确定切换模式为定制画面？'),
				onOk: async () => {
					set({ mode: 1 })
					if (state) {
						handleStopBatchPoll()
					}
				},
			})
		} else {
			confirmModal({
				msg: t('开启批量轮询将清空所有可用通道，您是否进行操作？'),
				onOk: async () => {
					set({ mode: 2, show_batch_poll: null })
				},
			})
		}
	},
	setHduShowName: async (flag) => {
		const { meetingMoid, correct_style } = get()
		if (!correct_style) {
			set({ show_mt_name: Number(flag) })
			return
		}
		const res = await fetchChangeIfShowMTName(meetingMoid, correct_style, Number(flag))
		res.success && set({ show_mt_name: Number(flag) })
		!res.success && Alert(res.description || t('操作失败'))
	},
	updateMyMeetingHdu: (data) => {
		const boxs = data.members
		let _my_hdu_cache: Array<MyHduCache> = []
		for (var i = 0; i < boxs.length; i++) {
			if (boxs[i].poll != null || boxs[i].vmp != null || boxs[i].spilt != null || boxs[i].spilt != null) {
				/**不是被会议自己占用的通道*/
				_my_hdu_cache.push({
					hdu_id: boxs[i].hdu_id,
					online: boxs[i].online,
				})
			}
		}
		set({ my_hdu_cache: _my_hdu_cache })
	},
	/**获取码率 */
	getRate: (type) => {
		let rate: number = 1
		const { config } = get()
		switch (type) {
			case 'preview':
				rate = config.previewW / config.containerW
				break
			case 'currentview':
				rate = config.currentviewW / config.containerW
				break
			case 'mcc':
				rate = config.MCCcontainerW / config.containerW
				break
		}
		return rate
	},
	/**编辑 */
	handleModifyIn: () => {
		set({ is_editing: true })
	},
	/**退出编辑 */
	handleModifyOut: () => {
		const { loadTvwallStyle, correct_style } = get()
		set({ is_editing: false })
		loadTvwallStyle(correct_style)
	},
	/**关闭电视墙模态框 */
	handleCloseTvwallModal: () => {
		const { reset, onClose } = get()
		onClose()
		reset()
	},
	/**停止批量轮询 */
	handleStopBatchPoll: async () => {
		const mask = Message.loading(t('正在处理，请稍候……'))
		const { meetingMoid, correct_style, show_mt_name, getMccTVWallsByMeetingMoid } = get()
		const params = {
			mode: 2,
			show_mt_name: show_mt_name,
			batch_poll: {
				state: 0,
			},
			members: [],
		}
		const res = await fetchChnageStyleInfo(meetingMoid, correct_style, params)
		if (res.success) {
			setTimeout(() => {
				set({ is_batch_poll: false })
				mask.hide()
			}, 2000)
		} else {
			mask.hide()
			Alert(res.description || '', function () {
				getMccTVWallsByMeetingMoid(meetingMoid)
			})
		}
	},
	convertMsg: (source) => {
		const { member_type, mt_id } = source
		var result: { [key: string]: any } = { mtid: '' }
		if ((member_type === 1 && !mt_id) || member_type === 0) {
			/**1-会控指定(并且没有终端) */
			return {
				type: 0,
				mt_id: '',
			}
		}
		if (member_type === 1 && mt_id) {
			/**1-会控指定(终端) */
			let _target = filterMtName(source)
			let _mtName = _target.name || ''
			return {
				type: member_type,
				_mtName: _mtName.replace(/\s/g, '&nbsp;'),
				..._target,
			}
		}
		if (
			member_type === 2 ||
			member_type === 3 ||
			member_type === 4 ||
			member_type === 6 ||
			member_type === 10 ||
			member_type === 11
		) {
			let _target = filterMtName(source) /**多流表示 */
			let _mtName = _target.name || ''
			return {
				type: member_type,
				name: getTvWallTypeName(member_type),
				_mtName: _mtName.replace(/\s/g, '&nbsp;'),
			}
		}
		if (member_type === 7) {
			//批量轮询时轮询到的终端
			let _target = filterMtName(source)
			let _mtName = _target.name || ''
			if (_mtName) {
				return {
					type: 7,
					mtName: _mtName.replace(/\s/g, '&nbsp;'),
				}
			} else {
				return { type: 0, mt_id: '' }
			}
		}
		if (member_type === 8) {
			/**自主多画面*/
			return {
				type: 8,
				mt_id: '',
				name: t('自主多画面'),
			}
		}
		if (member_type === 5) {
			/**单通道轮询 */
			const _cur_poll_mt = source.poll?.cur_poll_mt /**当前轮询到的终端 */
			filterMtName(_cur_poll_mt) /**多流表示 */
			const _mtName = _cur_poll_mt?.name || ''
			return {
				type: 5,
				name: t('单通道轮询'),
				mtName: _mtName.replace(/\s/g, '&nbsp;'),
			}
		}
		if (member_type === 9 /**四分屏*/) {
			return {
				type: 9,
				mt_id: '',
				name: t('四分屏'),
			}
		}
		return result
	},
	streamDomData: (mt) => {
		const { member_type, mt_id, stream, mt_key } = mt || {}
		return member_type === 1 && mt_id && stream === 1
			? { mt_key: mt_key, mt_id: mt_id }
			: { mt_key: null, mt_id: null }
	},
	removeStreamDom: () => {
		const {
			operateBoxInfo,
			operateBoxInfoIndex,
			boxDetailVOsSource,
			changeTVWallChannel,
			show_mt_name,
			getMTChnInfo,
		} = get()
		if (operateBoxInfo) {
			const callBack = (_position: number) => {
				let _boxDetailVOsSource = boxDetailVOsSource
					.map((item, index) => {
						if (index === _position) {
							return { member_type: 1, mt_id: '', hdu_id: item.hdu_id }
						}
						return null
					})
					.filter(Boolean)
				let _params = {
					mode: 1,
					show_mt_name: show_mt_name,
					batch_poll: null,
					members: _boxDetailVOsSource,
				}
				changeTVWallChannel(_params)
			}
			let { member_type, mt_id, stream } = operateBoxInfo
			if (member_type === 1 && mt_id && stream === 1) {
				getMTChnInfo(operateBoxInfo, (list: Array<chnInfoEntity>) => {
					let mtchnIds = list.map((x) => x.v_snd_chn_id).sort((a: number, b: number) => a - b)
					let _res = [
						boxDetailVOsSource[operateBoxInfoIndex - 2],
						boxDetailVOsSource[operateBoxInfoIndex - 1],
						boxDetailVOsSource[operateBoxInfoIndex],
						boxDetailVOsSource[operateBoxInfoIndex + 1],
						boxDetailVOsSource[operateBoxInfoIndex + 2],
					]
					let _res1 = [_res[0], _res[1], _res[2]],
						_res2 = [_res[1], _res[2], _res[3]],
						_res3 = [_res[2], _res[3], _res[4]]
					if (_res3.filter((x) => x?.mt_id).length > 1) {
						let ids = _res3.map((x) => x?.mt_chn_id ?? NaN)
						if (isEqualMtchnids(ids, mtchnIds)) {
							callBack(operateBoxInfoIndex + 1)
							callBack(operateBoxInfoIndex + 2)
							set({ globalSwitchView: {} })
							return
						}
					}
					if (_res2.filter((x) => x?.mt_id).length > 1) {
						let ids = _res2.map((x) => x?.mt_chn_id ?? NaN)
						if (isEqualMtchnids(ids, mtchnIds)) {
							callBack(operateBoxInfoIndex + 1)
							callBack(operateBoxInfoIndex - 1)
							set({ globalSwitchView: {} })
							return
						}
					}
					if (_res1.filter((x) => x?.mt_id).length > 1) {
						let ids = _res1.map((x) => x?.mt_chn_id ?? NaN)
						if (isEqualMtchnids(ids, mtchnIds)) {
							callBack(operateBoxInfoIndex - 1)
							callBack(operateBoxInfoIndex - 2)
							set({ globalSwitchView: {} })
							return
						}
					}
				})
			}
		}
	},
	/**改变通道请求 */
	changeTVWallChannel: async (parsms) => {
		const { meetingMoid, correct_style, loadTvwallStyle } = get()
		const res = await fetchChnageStyleInfo(meetingMoid, correct_style, parsms)
		if (res.success) {
		} else {
			Alert(res.description || '', function () {
				loadTvwallStyle(correct_style)
			})
		}
	},
	/**获取终端的音视频通道 */
	getMTChnInfo: function (mt, callBack) {
		const { meetingMoid } = get()
		let mt_id = mt.mt_id
		if (mt.id === '0_1') {
			//是上级会议
			let mtids = mt.mt_id.split(/[\._]/)
			mt_id = mtids[mtids.length - 1]
		}
		fetchGetMTChnInfo(meetingMoid, mt_id).then((res) => {
			if (res.success) {
				let _result: Array<chnInfoEntity> = []
				if (res.list.length > 0 && res.list[0] == null) {
					_result = []
				} else {
					_result = res.list
				}
				callBack && callBack(_result)
			} else {
				Alert(t('获取终端信息失败'))
			}
		})
	},
	/**切换画面合成通道*/
	handleSendChannelVmp: async (vmp) => {
		const { changeTVWallChannel, show_mt_name, boxDetailVOsSource, operateBoxInfoIndex } = get()
		let _boxDetailVOsSource = boxDetailVOsSource
			.map((item, index) => {
				if (index === operateBoxInfoIndex) {
					return {
						member_type: 8,
						vmp: vmp,
						hdu_id: item.hdu_id,
					}
				}
				return null
			})
			.filter(Boolean)
		const params = {
			mode: 1,
			show_mt_name: show_mt_name,
			batch_poll: null,
			members: _boxDetailVOsSource,
		}
		changeTVWallChannel(params)
	},
	removeErrorMark: (_hdu_id) => {
		const { boxDetailVOsSourceErrorCode } = get()
		let _result = boxDetailVOsSourceErrorCode || {}
		let _key = _hdu_id || ''
		_result[_key] = ''
		set({ boxDetailVOsSourceErrorCode: _result })
	},
	msgHandle: (_data) => {
		const { isOpen, correct_style, removeErrorMark, boxDetailVOsSource, is_editing } = get()
		let _style_id = _data.style_id /**风格style_id */
		let _hdu_id = _data.member?.hdu_id /**对应的hdu_id*/
		let _pre_name = _data.name || '' /**预案名称 */
		let _show_mt_name = _data.show_mt_name /**是否显示终端名称 */
		let _member_type = _data.member?.member_type /**终端的跟随类型 */
		let _mt_id = _data.member?.mt_id /**终端的mt_id */
		let _mode = _data.mode /**终端的mt_id */
		const meetingType = useMccStore.getState().mccInfo.meetingType /**会议类型 */
		removeErrorMark(_hdu_id) /**删除错误提示*/
		if (!isOpen) return /**弹框未开启 */
		// if (!((_member_type === 1 && _mt_id) || _member_type !== 1)) return /**终端不存在之 */
		/**更新是否显示终端名称 */
		set({ preName: _pre_name, mode: _mode })
		if (Number.isInteger(_show_mt_name)) {
			if (!is_editing) {
				set({ show_mt_name: _show_mt_name })
			}
		}
		if (_style_id === correct_style) {
			if (_member_type === 1 && !_mt_id) {
				/**代表删除*/
				let _members = boxDetailVOsSource.map((item) => {
					if (item.hdu_id === _hdu_id) {
						return _data.member
					}
					return item
				})
				set({ boxDetailVOsSource: _members })
				removeErrorMark(_hdu_id)
			} else {
				//如果是四分屏  在有选看终端情况下不删除
				if (_member_type !== 9 || (_member_type !== 9 && !_mt_id)) {
					removeErrorMark(_hdu_id)
				}
				if (!(_member_type === 9 && meetingType === 1)) {
					//如果是端口会议，且是四分屏时，不能展示出来
					let _members = boxDetailVOsSource.map((item) => {
						if (item.hdu_id === _hdu_id) {
							return Object.assign({}, _data.member, { is_mine: 1, is_online: 1, is_used: 1 })
						}
						return item
					})
					set({ boxDetailVOsSource: _members })
				}
			}
		}
	},
	checkCurStyle: (_data) => {
		//根据推送消息的 风格/pollId 判定消息是否需要处理
		const { correct_style, batch_poll } = get()
		let _style_id = _data.style_id
		let _batch_id = _data.batch_poll?.batch_id /**当前的批量轮询的id */
		/**将最新的风格携带的批量轮询更新到当前数据*/
		if (_style_id === correct_style) {
			if (_batch_id) {
				let _result = Object.assign({}, batch_poll, { batch_id: _batch_id })
				set({ batch_poll: _result })
			}
			return true
		}
		if (_batch_id === batch_poll?.batch_id) {
			//停止批量轮询消息不带回style 字段,通过pollId判定是否当前风格
			return true
		}
		return false
	},
	batchpollhandle: (_data) => {
		// 批量轮询,单独的一个消息体
		const { is_editing, checkCurStyle, isOpen } = get()
		const _state = _data.batch_poll.state || 0 /**当前的批量轮询状态 */
		let _show_mt_name = _data.show_mt_name /**是否显示终端名称*/
		if (!isOpen) return
		if (is_editing && _state) return //编辑状态，且不是停止轮询，不处理
		if (!checkCurStyle(_data)) {
			//不是当前风格
			return false
		}
		if (Number.isInteger(_show_mt_name)) {
			set({ show_mt_name: _show_mt_name })
		}
		const {
			id = '',
			keep_time = 30,
			num = 0,
			name = '',
			members = [],
			mode = 1,
			cur_poll_mt = undefined,
			batch_id = '',
		} = _data.batch_poll || {}
		let _show_batch_poll = {
			id: id,
			keep_time: keep_time,
			num: num,
			name: name,
			members: members,
			mode: mode,
			cur_poll_mt,
		}
		set({
			state: _state || 0 /**批量轮询状态 */,
			batch_poll: Object.assign({ batch_id: batch_id }, _show_batch_poll),
			show_batch_poll: new Poll(_show_batch_poll),
			is_batch_poll: _state ? true : false,
		})
		if (_state) {
			set({ mode: 2 })
		} else {
			set({ mode: 1 })
		}
	},
	errorHandle: (_data) => {
		const { correct_style } = get()
		if (_data.hdu_style === correct_style) {
			//对错误码进行延时处理,兼容消息推送时序
			setTimeout(function () {
				let _key = _data.hdu_id
				let _value = _data.err_code
				let _result: any = {}
				_result[_key] = _value
				set({ boxDetailVOsSourceErrorCode: _result })
				if (_value === '28004') {
					set({ isFourScreenOpen: false })
				}
			}, 500)
		}
	},
}))
export const useTvWallStore = create(store)
